package io.gitee.thghh.generate.core;

import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import liquibase.analytics.configuration.AnalyticsArgs;
import liquibase.configuration.ConfigurationDefinition;
import liquibase.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * 启动类
 *
 * @author pengzhikang
 * @date 2025/3/27 11:55
 * @since 1.0.0
 */
@Slf4j
@SpringBootApplication
@EnableEncryptableProperties
public class CodeApplication {

    public static void main(String[] args) {
        try {
            // disable sending product usage data and analytics to Liquibase
            FieldUtils.writeDeclaredField(AnalyticsArgs.ENABLED, "defaultValue", Boolean.FALSE, true);

            SpringApplicationBuilder builder = new SpringApplicationBuilder(CodeApplication.class);
            //设置headless=false，设置web为none
            ConfigurableApplicationContext context = builder.headless(false).web(WebApplicationType.NONE).run(args);

            ConfigurableEnvironment environment = context.getEnvironment();
            String applicationName = environment.getProperty("spring.application.name");

            System.out.println(applicationName + " start");
        } catch (Exception e) {
            log.error("程序启动失败", e);
        }


    }
}
